package game.gol;

import game.console.IConsoleCommand;

import java.util.ArrayList;
import java.util.List;

public class GameOfLifeCommands
{
    public static List<IConsoleCommand> getCommands()
    {
        final GameOfLife gol = GameOfLife.getInstance();
        
        List<IConsoleCommand> commands = new ArrayList<IConsoleCommand>();
        commands.add(new IConsoleCommand()
        {
            @Override
            public String getCommand()
            {
                return "pause";
            }
            
            @Override
            public String getInfo()
            {
                return "pause - pause game - 'pause'";
            }
            
            @Override
            public String[] fireCommand(String command)
            {
                gol.pause();
                return new String[] { "Pause = " + gol.isPaused() };
            }
        });
        commands.add(new IConsoleCommand()
        {
            @Override
            public String getCommand()
            {
                return "rule";
            }
            
            @Override
            public String getInfo()
            {
                return "rule  - change gol rule, param is gol-rule-syntax SURVIVE/BIRTH - 'rule 23/3'";
            }
            
            @Override
            public String[] fireCommand(String command)
            {
                String rule = command.substring("rule ".length());
                gol.setRule(rule);
                return new String[] { "NEW RULE: '" + rule + "'" };
            }
        });
        commands.add(new IConsoleCommand()
        {
            @Override
            public String getCommand()
            {
                return "color";
            }
            
            
            @Override
            public String getInfo()
            {
                return "color - change color, available colors: 0 = (green, red, black), 1 = (black, white)";
            }
            
            @Override
            public String[] fireCommand(String command)
            {
                String color = command.substring("color ".length());
                gol.setColorSet(ColorSet.getById(color));
                return new String[] { "NEW COLOR: '" + color + "'" };
            }
        });
        commands.add(new IConsoleCommand()
        {
            @Override
            public String getCommand()
            {
                return "lc%";
            }
            
            @Override
            public String getInfo()
            {
                return "lc%   - change living cells % of total cells on next restart, WARNING performance decreases extremely when % is greater than 50";
            }
            
            @Override
            public String[] fireCommand(String command)
            {
                int prozent = Integer.parseInt(command.substring("lc% ".length()));
                gol.setProzentLivingCells(prozent);
                return new String[] { "LIVING CELLS ON RESTART: " + prozent + " %" };
            }
        });
//        commands.add(new IConsoleCommand() {
//            
//            @Override
//            public String getCommand()
//            {
//                return "?";
//            }
//            
//            @Override
//            public String[] fireCommand(String command)
//            {
//                consoleBuffer
//                consoleBuffer.add("pause - pause game - 'pause'");
//                consoleBuffer.add("rule  - change gol rule, param is gol-rule-syntax SURVIVE/BIRTH - 'rule 23/3'");
//                consoleBuffer.add("color - change color, available colors: 0 = (green, red, black), 1 = (black, white)");
//                consoleBuffer.add("lc%   - change living cells % of total cells on next restart, WARNING performance decreases extremely when % is greater than 50");
//                return new String[] { null;
//            }
//        })
        return commands;
    }
}
